#include <assert.h>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include <assert.h>

#include "dominion.h"
#include "dominion_helpers.h"
#include "rngs.h"
#include "testutils.h"

/*
 * +1 card with cose >= 2 more than trashed card.
 */
void remodel_test(void)
{
	int i, j;
	int choice1, choice2;
	int prev_choice1_count;
	int effect_result;
	int discard_choice;
	struct gameState state;

	init_test_date(&state, 1);

	srand(time(NULL));

	for (i = 0; i < MAX_ITERATIONS; i++) {
		state.deckCount[0] = 50;
		for (j = 0; j < state.deckCount[0]; j++) {
			state.deck[0][j] = random_card();
		}

		state.handCount[0] = 5;
		for (j = 0; j < 4; j++) {
			state.hand[0][j] = random_card();
		}
		state.hand[0][4] = remodel;

		choice1 = rand() % 3;
		choice2 = random_card();

		prev_choice1_count = card_count(state.hand[0], state.hand[0][choice1], state.handCount[0]);

		discard_choice = state.hand[0][choice1];

		effect_result = remodel_effect(&state, 0, choice1, choice2, 4);

		assert(state.handCount[0] == 5);

		if (effect_result != -1) {

			if (card_count(state.hand[0], state.hand[0][choice1], state.handCount[0]) >= prev_choice1_count
				&& choice2 != discard_choice) {
				printf("FAIL: iteration %d - discarding choice1 bug.\n". i);
			}

			if (getCost(choice2) < getCost(discard_choice) + 2) {
				printf("FAIL: iteration %d - did not fail on cost bug.\n", i);
			}
		} else {
			if (card_count(state.hand[0], state.hand[0][choice1], state.handCount[0]) < prev_choice1_count
				&& choice2 != discard_choice) {
				printf("FAIL: iteration %d - discarding choice1 bug false positive.\n". i);
			}

			if (getCost(choice2) >= getCost(discard_choice) + 2) {
				printf("FAIL: iteration %d - did not fail on cost bug false positive.\n", i);
			}
		}
	}
}

int main(int argc, char const *argv[])
{
	remodel_test();
	return 0;
}